
#define RUNTIME_DBG_LVL 0
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <dbg.h>
// #include <ddblk/syslock.h>
#include <ddblk/locks.h>
#include "dblk_test.h"
/* 定义clh和mcs */
DEF_LOCKNODE_ALIGNMALLOC(alignlknode, HDEF_CACHE_LINE_BYTES)

DEF_NLOCK(clh, clh, OUFUN_OF(spin_wait), OUFUN_OF(alignlknode))
DEF_NLOCK(clh, bounded_clh, OUFUN_OF(spin_wait_bounded), OUFUN_OF(alignlknode))
DEF_NLOCK(clh, futex_clh, OUFUN_OF(futex_wait), OUFUN_OF(alignlknode))

DEF_NLOCK(mcs, mcs, OUFUN_OF(spin_wait), OUFUN_OF(alignlknode))
DEF_NLOCK(mcs, bounded_mcs, OUFUN_OF(spin_wait_bounded), OUFUN_OF(alignlknode))
DEF_NLOCK(mcs, futex_mcs, OUFUN_OF(futex_wait), OUFUN_OF(alignlknode))


int test_clh(){
	SIMPLE_LOCKTEST(clh);
	SIMPLE_LOCKTEST_RELAX(clh);
	SIMPLE_LOCKTEST(bounded_clh);
	SIMPLE_LOCKTEST_RELAX(bounded_clh);
	SIMPLE_LOCKTEST(futex_clh);
	SIMPLE_LOCKTEST_RELAX(futex_clh);

	/* 测试失败的情况, 可能有死锁 */
	// TIMEOUT_LOCKTEST(bounded_clh);
	return 0;
}

int test_mcs(){
	SIMPLE_LOCKTEST(mcs);
	SIMPLE_LOCKTEST_RELAX(mcs);
	SIMPLE_LOCKTEST(bounded_mcs);
	SIMPLE_LOCKTEST_RELAX(bounded_mcs);
	SIMPLE_LOCKTEST(futex_mcs);
	SIMPLE_LOCKTEST_RELAX(futex_mcs);

	/* 测试失败的情况 */
	// TIMEOUT_LOCKTEST(bounded_mcs);
	return 0;
}

int main(){
	test_clh();
	test_mcs();
	return 0;
}
